package com.dkd.generator;

import com.dkd.generator.util.VelocityInitializer;
import org.apache.velocity.Template;
import org.apache.velocity.VelocityContext;
import org.apache.velocity.app.Velocity;

import java.io.FileWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

import static java.util.List.*;

public class velocitytest {
    public static void main(String[] args) throws Exception{
//        1.初始化模板引擎
        VelocityInitializer.initVelocity();
        /*2.准备数据模型*/
        VelocityContext velocityContext = new VelocityContext();
        velocityContext.put("message","加油少年！！");
//        创建区域对象
        Region region = new Region(1,"北京市西城区");
        Region region2 = new Region(2,"北京市北五环");
        velocityContext.put("region",region);
        List<Region> regions =new ArrayList<>();
        regions.add(region);
        regions.add(region2);
        velocityContext.put("regions",regions);
//        3.读取模版
        Template template = Velocity.getTemplate("vm/vctemplate.vm","UTF-8");
//        4.渲染模版
        FileWriter fileWriter = new FileWriter("D:\\.Alearn\\Ruoyi\\workspace\\index.htm");
        template.merge(velocityContext,fileWriter);
        try {
            fileWriter.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
